'use strict';
//////////////////////////////////////////////////////////////////////////////
// 统一整理规则 如校验规则 或者其他
// =====================
// liuyp 2019年6月13日18:17:11
//////////////////////////////////////////////////////////////////////////////
// 正则校验规则
// ---------------------------
// 图表动画规则
var seq = 0, delays = 80, durations = 500;
// ---------------------------
function $rule() {
    // 校验方法汇总
    return {
        isNumFixed2: function(value) {
            if (!value) { return true }
            return value.toString() === parseFloat(value).toFixed(2).toString()
        },
        isNum: function(value) {
            if (!value) { return true }
            return value.toString() === parseInt(value).toString()
        },
        isNumFixed012: function(value) {
            if (!value) { return true }
            return value.toString() === parseInt(value).toString()
            || value.toString() === parseFloat(value).toFixed(1).toString()
            || value.toString() === parseFloat(value).toFixed(2).toString()
        },
        chartEvents1: {
            created: function() { seq = 0; },
            draw: function(data) {
                seq++;
                var axis = data.axis&&data.axis.units&&data.axis.units.pos;
                if(data.type === 'line') {
                    // If the drawn element is a line we do a simple opacity fade in. This could also be achieved using CSS3 animations.
                    data.element.animate({
                        opacity: { begin: seq * delays + 1000, dur: durations, from: 0, to: 1 }
                    });
                } else if(data.type === 'label' && axis === 'x') {
                    data.element.animate({
                        y: { begin: seq * delays, dur: durations, from: data.y + 100, to: data.y, easing: 'easeOutQuart' }
                    });
                } else if(data.type === 'label' && axis === 'y') {
                    data.element.animate({
                        x: { begin: seq * delays, dur: durations, from: data.x - 100, to: data.x, easing: 'easeOutQuart' }
                    });
                } else if(data.type === 'point') {
                    data.element.animate({
                        x1: { begin: seq * delays, dur: durations, from: data.x - 10, to: data.x, easing: 'easeOutQuart' },
                        x2: { begin: seq * delays, dur: durations, from: data.x - 10, to: data.x, easing: 'easeOutQuart' },
                        opacity: { begin: seq * delays, dur: durations, from: 0, to: 1, easing: 'easeOutQuart' }
                    });
                } else if(data.type === 'grid') {
                    // Using axis we get x or y which we can use to construct our animation definition objects
                    var pos1Animation = { begin: seq * delays, dur: durations, from: data[axis + '1'] - 30, to: data[axis + '1'], easing: 'easeOutQuart' };
                    var pos2Animation = { begin: seq * delays, dur: durations, from: data[axis + '2'] - 100, to: data[axis + '2'], easing: 'easeOutQuart' };
                    var animations = {};
                    animations[axis + 'x1'] = pos1Animation;
                    animations[axis + 'x2'] = pos2Animation;
                    animations['opacity'] = { begin: seq * delays, dur: durations, from: 0, to: 1, easing: 'easeOutQuart' };
                    data.element.animate(animations);
                }
            }
        }
    };
}
exports = module.exports = $rule;